home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wink / source / wink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  7.4 KB  |  374 lines

  1. /************************************************************
  2.  
  3.     FM-TOWNS Text Screen Editer Program
  4.  
  5.     1989.7.27   v1.00   Make By Ken
  6.  
  7. ************************************************************/
  8. #include    <stdio.h>
  9. #include    <stdlib.h>
  10. #include    <setjmp.h>
  11. #include    <string.h>
  12. #define MAIN
  13. #include    "defs.h"
  14.  
  15. #ifdef    FMR70
  16. #include    <signal.h>
  17. #endif
  18.  
  19. #ifdef  TOWNS
  20. #include    <egb.h>
  21. #include    <fmc.h>
  22. #include    <snd.h>
  23. #include    "oaklib.h"
  24. #define    unlink(f) remove(f)
  25. #endif
  26.  
  27. extern void wrtstr();
  28. extern void Dsp_ins_mode();
  29. extern void Dsp_free();
  30. extern void Ins_buf();
  31. extern void Cut_buf();
  32. extern int  Dsp_init();
  33. extern int  Bfp_init();
  34. extern void Set_vram();
  35. extern void Dsp_vram();
  36. extern BOOL edit();
  37. extern int  Del_wind();
  38. extern void Bfp_end();
  39. extern void RSB_end();
  40. extern void putstr();
  41. extern void putsys();
  42. extern void putmode();
  43. extern void Dmy_form();
  44. extern void Del_buf();
  45. extern void Auto_log_init();
  46. extern void CD_endof();
  47.  
  48. extern UCHAR vram[];
  49. extern char  *SPCSTR;
  50. extern char  *Auto_log_file;
  51.  
  52. extern short int modeW;
  53.  
  54.     char     *work;
  55.     jmp_buf mark;
  56.     char    *file_name=NULL;
  57.     char    *Tmp_device_name=NULL;
  58.  
  59. static BOOL    old_wrt_flg=ERR;
  60. static char     tmp_name[160];
  61. static int    Back_up = FALSE;
  62. static int    Apend_Z = FALSE;
  63.  
  64. void    Start_Msg()
  65. {
  66.     static char *msg[]={
  67.     "           WINK @ー            ",
  68.     "   Multi Screen Text Editor   ",
  69.     "    WINK  [ver3.20.00]    ",
  70.     " Copyright (c) 1989,90 FTOWNS ",
  71.     "    Created by K.Miyazaki     ",
  72.     "       thanks to RED++        ",
  73.     NULL
  74.     };
  75.     int     i;
  76.     char    tmp[160];
  77.  
  78.     Dmy_form(tmp,30,0x98,0x95,0x99); 
  79.     wrtstr(tmp,20,9,0x07);
  80.     Dmy_form(tmp,30,0x96,0x20,0x96); 
  81.     for ( i = 0 ; msg[i] != NULL ; i++ ) {
  82.         wrtstr(tmp,20,10+i,0x07);
  83.         wrtstr(msg[i],21,10+i,i == 0 ? 0x14 : 0x07);
  84.     }
  85.     Dmy_form(tmp,30,0x9A,0x95,0x9B); 
  86.     wrtstr(tmp,20,16,0x07);
  87.     wrtstr("WINK",25,12,0x16);
  88. }
  89. void    Gra_init()
  90. {
  91. #ifdef    TOWNS
  92.     work = (char *)malloc(2048);
  93.     memset(work,0,2048);
  94.     EGB_init(work,2048);
  95.     EGB_resolution(work, 0, 3);
  96.     EGB_resolution(work, 1, 3);
  97.     EGB_displayPage(work, 0, 3);
  98.     EGB_pen(work,0);
  99.     EGB_penSize(work,1);
  100.     SND_elevol_init();
  101.     SND_elevol_mute(0x30);
  102.     SND_elevol_set(1,64,64);
  103. #endif
  104. }
  105. void    Dsp_file_name()
  106. {
  107.     char    tmp[160];
  108.  
  109.     memset(tmp,' ',60); tmp[60] = '\0';
  110.     wrtstr(tmp,0,1,0x1F);
  111.     if ( file_name != NULL ) {
  112.     sprintf(tmp," %-12s ",file_name);
  113.     wrtstr(tmp,0,1,0x14);
  114.     } else
  115.     wrtstr("  [Not File]  ",1,1,0x1F);
  116. }
  117. void    Dsp_wrt_flg()
  118. {
  119.     if ( Wrt_flg != old_wrt_flg ) {
  120.     if ( (old_wrt_flg = Wrt_flg) == FALSE )
  121.         wrtstr("表示",0,0,0x17);
  122.     else
  123.         wrtstr("編集",0,0,0x17);
  124.     }
  125. }
  126. void    Dsp_PFKEY()
  127. {
  128.     int     i;
  129.     static char *menu[]={
  130.     " MENU1"," MENU2"," MENU3"," MENU4","CD演奏",
  131.     " 選択 "," 削除 "," 確定 "," 複写 "," 通信 " };
  132.  
  133.     for ( i = 0 ; i < 10 ; i++ )
  134.         wrtstr(menu[i],i*7+(i/5),MENU_Y,0x1F);
  135. }
  136. void    Dsp_status()
  137. {
  138.     UCHAR   tmp[100];
  139.  
  140.     memset(tmp,' ',80); tmp[80] = '\0';
  141.     wrtstr(tmp,0,0,0x1F);
  142.     wrtstr(tmp,0,1,0x1F);
  143.     Dsp_ins_mode();
  144.     Dsp_file_name();
  145.     Dsp_wrt_flg();
  146.     Dsp_free();
  147.     Dsp_PFKEY();
  148. }
  149. int     Buf_init(file)
  150. char    *file;
  151. {
  152.     int        n;
  153.     FILE    *fp;
  154.     UCHAR   tmp[512];
  155.  
  156.     top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
  157.     if ( file != (char *)NULL && (fp = fopen(file,"rb")) != (FILE *)NULL ) {
  158.     wrtstr("ファイルを読み込んでいます",30,1,0x15);
  159.     while ( (n = fread(tmp,1,512,fp)) > 0 ) {
  160.         Ins_buf(btm_ptr,n,tmp);
  161.         btm_ptr += n;
  162.     }
  163.     if ( btm_ptr > 0 && *Cnv_ptr(btm_ptr-1) == '\x1A' )
  164.         Del_buf(--btm_ptr,1L);
  165.     file_name = file;
  166.     fclose(fp);
  167.     wrtstr(SPCSTR,30,1,0x1F);
  168.     } else
  169.     file_name = file;
  170.  
  171.     chk_ptr = cke_ptr = ERR;
  172.     Wrt_flg = FALSE;
  173.     old_wrt_flg = TRUE;
  174.  
  175.     return FALSE;
  176. }
  177. int    save(file)
  178. char    *file;
  179. {
  180.     FILE    *fp;
  181.     UCHAR   tmp[256];
  182.     int        n;
  183.     LONG    sp,sz;
  184.     char    *p;
  185.  
  186.     if ( file != NULL ) {
  187.     file_name = file;
  188.     Dsp_file_name();
  189.     }
  190.     if ( file_name == NULL )
  191.     return ERR;
  192.  
  193.     if ( Back_up != FALSE ) {
  194.     strcpy((char *)tmp,file_name);
  195.     if ( (p = strrchr((char *)tmp,'.')) == NULL )
  196.         for ( p = (char *)tmp ; *p != '\0' ; p++ );
  197.     strcpy(p,".BAK");
  198.     unlink((char *)tmp);
  199.     rename(file_name,(char *)tmp);
  200.     }
  201.  
  202.     if ( (fp = fopen(file_name,"wb")) == NULL )
  203.     return ERR;
  204.  
  205.     for ( sp = 0,sz = btm_ptr ; sz > 0 ; ) {
  206.     if ( sz < 256 ) n = sz; else n = 256;
  207.         Cut_buf(tmp,n,sp);
  208.     fwrite(tmp,1,n,fp);
  209.     sp += n;
  210.     sz -= n;
  211.     }
  212.  
  213.     if ( Apend_Z == FALSE ) {
  214.     tmp[0] = 0x1A;
  215.     fwrite(tmp,1,1,fp);
  216.     }
  217.  
  218.     if ( ferror(fp) ) {
  219.     fclose(fp);
  220.     return ERR;
  221.     }
  222.     fclose(fp);
  223.     return FALSE;
  224. }
  225. void    Set_file_name(file)
  226. char    *file;
  227. {
  228.     strcpy(tmp_name,file);
  229.     file_name = tmp_name;
  230.     Dsp_file_name();
  231. }
  232. void    Set2_file_name(file)
  233. char    *file;
  234. {
  235.     strcpy(tmp_name,file);
  236.     file_name = tmp_name;
  237. }
  238. void    main(argc,argv)
  239. int    argc;
  240. char    *argv[];
  241. {
  242.     int     i;
  243.     char    tmp[40];
  244.     char    *p;
  245.     char    *file=NULL;
  246.  
  247.     CONTRL = 0;
  248.     TAB = 8;
  249.  
  250. #ifdef    FMR70
  251.     signal(SIGINT,SIG_IGN);
  252. #endif
  253.  
  254.     while ( --argc > 0 ) {
  255.     p = *(++argv);
  256.     if ( *p == '-' || *p == '/' ) {
  257.         switch(*(++p)) {
  258.         case 'A': case 'a':
  259.             Auto_log_file = ++p;
  260.             break;
  261.         case 'B': case 'b':
  262.             Back_up = TRUE;
  263.             break;
  264.         case 'Z': case 'z':
  265.             Apend_Z = TRUE;
  266.             break;
  267.         case 'R': case 'r':
  268.             modeW = (modeW & 0xFFF3) | 0x0008;
  269.             break;
  270.         case 'F': case 'f':
  271.             modeW = (modeW & 0xFFCF) | 0x0020;
  272.             break;
  273.         case 'K': case 'k':
  274.             modeW = (modeW & 0xFE3F) | 0x0080;
  275.             break;
  276.         case 'H': case 'h':
  277.             modeW = (modeW & 0xFE3F) | 0x0100;
  278.             break;
  279.         case 'T': case 't':
  280.             Tmp_device_name = ++p;
  281.             break;
  282.         case 'D': case 'd':
  283.             TAB = atoi(++p);
  284.             break;
  285.         }
  286.     } else
  287.         file = p;
  288.     }
  289.  
  290.     Gra_init();
  291.     Dsp_init();
  292.     KAN_open(putstr,putsys,putmode);
  293.     KYB_clic(1);
  294.     Auto_log_init();
  295.     Dsp_status();
  296.     Start_Msg();
  297.  
  298.     if ( Bfp_init() != FALSE ) {
  299.     wrtstr("メモリ管理の初期化に失敗しました",30,1,0x12);
  300.     exit(0);
  301.     }
  302.     if ( Buf_init(file) != FALSE ) {
  303.     wrtstr("ファイルの初期化に失敗しました",30,1,0x12);
  304.     exit(0);
  305.     }
  306.  
  307.     Dsp_status();
  308.     Set_vram();
  309.     Dsp_vram(vram);
  310.  
  311.     if ( (i = setjmp(mark)) != 0 ) {
  312.     sprintf(tmp,"致命的なエラ-が発生しました #%d",i);
  313.     wrtstr(tmp,30,1,0x12);
  314.     }
  315.  
  316.     do {
  317.         while ( edit() == FALSE );
  318.     } while ( Del_wind() == FALSE );
  319.  
  320.     Bfp_end();
  321.     RSB_end();
  322.     KYB_clic(1);
  323.  
  324. #ifdef    TOWNS
  325.     KAN_close();
  326.     CD_endof();
  327. #endif
  328.  
  329. #ifdef    FMR70
  330.     cprintf("\x1B[2J");
  331. #endif
  332. }
  333.  
  334. #ifdef    FMR70
  335. #include    <dos.h>
  336.  
  337. int     KYB_clic(sw);
  338. int    sw;
  339. {
  340.     union REGS    regs;
  341.  
  342.     regs.h.ah = 0x05;
  343.     regs.h.al = sw;
  344.     int86(0x90,®s,®s);
  345.     return;
  346. }
  347. int    kbhit()
  348. {
  349.     union REGS    regs;
  350.  
  351.     regs.h.ah = 0x07;
  352.     int86(0x90,®s,®s);
  353.     return (int)regs.h.al;
  354. }
  355. int    KYB_read(sw,ec)
  356. int    sw;
  357. unsigned *ec;
  358. {
  359.     union REGS    regs;
  360.  
  361.     regs.h.ah = 0x09;
  362.     regs.h.al = sw;
  363.     int86(0x90,®s,®s);
  364.     *ec = regs.x.bx;
  365.     if ( *ec >= 0x5D00 && *ec <= 0x6600 ) {
  366.         regs.h.ah = 0x09;
  367.         regs.h.al = sw;
  368.         int86(0x90,®s,®s);
  369.         *ec = regs.x.bx;
  370.     }
  371.     return regs.x.dx;
  372. }
  373. #endif
  374.